/ leetcodesolve / Container With Most Water.py
swadhinbiswas update · 4/24/2024
52d2041
30 lines · 571 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#Broutforce method
from typing import List
class Solution:
    def maxArea(self, height: List[int]) -> int:

        if len(height)<=2:
           return height[0]*1


        else:
            res=0
            l,r=0,len(height)-1

            while l<r:
                area=(r-1)*min(height[l], height[r])
                res=max(res, area)
                
                if height[l]<height[r]:
                    l+=1
                else:
                    r-=1

            return res


height =[1,1]
soluction=Solution()
x=soluction.maxArea(height)
print(x)